<%--
  Created by IntelliJ IDEA.
  User: 惠普
  Date: 2020/6/2
  Time: 9:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="true" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>

<html>
<head>
    <title>退货原因设置</title>
    <%@include file="/common/header.jsp"%>
</head>
<body>
<div id="root">
    <Card style="margin: 20px 0" >
        <Icon type="ios-film-outline"></Icon>
        数据列表
        <shiro:hasPermission name="reason:add">
        <i-button type="default" style="margin-left: 1000px" @click="add">添加</i-button>
        </shiro:hasPermission>
    </Card>
    <i-table :columns="column" :data="data" @on-selection-change="tableSelect=arguments[0]" border stripe height="400">
        <template slot-scope="{row,index}" slot="returnState" >
            <%--<i-switch :value="scope.row.factoryStatus === 1?true:false" @on-change="change" />--%>
                <i-switch :value="row.returnState == 1?true:false" @on-change="change(row,index)" />
            <%--{{scope.row.factoryStatus}}--%>
        </template>
        <template slot-scope="{row,index}" slot="action">
            <shiro:hasPermission name="reason:update">
            <i-button type="default"  @click="update(row,index)">修改</i-button>
            </shiro:hasPermission>
            <shiro:hasPermission name="reason:del">
             <i-button type="default"  @click="del(row,index)">删除</i-button>
            </shiro:hasPermission>
        </template>
    </i-table>
    <template>
        <Page :total="total1"
              :page-size="pageSize"
              :current.sync="pageNo"
              show-total
              show-sizer
              :page-size-opts="[5,10,15,20]"
              style="margin-left: 30%;"
              @on-page-size-change="pageSize=arguments[0];getList();"
              @on-change="getList"/>
    </template>
    <Modal  v-model="modaladd"  title="添加原因" @on-ok="doadd">
        <i-form :label-width="80">
            <Form-Item label="原因类型:">
                <i-input v-model="ReturnReason.returnName"></i-input>
            </Form-Item>
            <Form-Item label="排序:">
                <Input-Number min="1" v-model="ReturnReason.returnSort"></Input-Number >
            </Form-Item>
            <Form-Item label="是否启用:">
                <Radio-Group v-model="ReturnReason.returnState">
                    <Radio label="1">
                        <span>是</span>
                    </Radio>
                    <Radio label="0">
                        <span>否</span>
                    </Radio>
                </Radio-Group>
            </Form-Item>
        </i-form>
    </Modal>
    <Modal  v-model="modalupdate"  title="修改原因" @on-ok="doupdate" @on-cancel="noupdate">
        <i-form :label-width="80">
            <Form-Item label="原因类型:">
                <i-input v-model="ReturnReason.returnName"></i-input>
            </Form-Item>
            <Form-Item label="排序:">
                <Input-Number min="1" v-model="ReturnReason.returnSort"></Input-Number >
            </Form-Item>
            <Form-Item label="是否启用:">
                    <i-switch true-value="1" false-value="0" v-model="ReturnReason.returnState"/>
            </Form-Item>
        </i-form>
    </Modal>
</div>
</body>
<script>
    new Vue({
        el:"#root",
        data:{
            column:[
                // {
                //     type: "selection",
                //     width: 60,
                //     align: "center"
                // },
                {title:"编号",key:"id"},
                {title:"原因类型",key:"returnName"},
                {title:"排序",key:"returnSort"},
                {title:"是否可用",slot:"returnState",width: "120%"},
                {title:"添加时间",key:"returnTime"},
                {title:"操作",slot:"action"}
            ],
            data:[],
            modaladd:false,
            modalupdate:false,
            ReturnReason:{},
            total1:{},
            pageSize:5,
            pageNo:1
        },
        mounted(){
            this.getList();
        },
        methods:{
            getList(){
                axios.post(`/ord/reason/list/${this.pageSize}/${this.pageNo}`,this.ReturnReason).then(
                    ({data})=>{
                        this.data=data.result.list;
                        this.total1 = data.result.total
                    }
                )
            },
            getReasonList(){
                axios.post("/ord/reason/reasonList")
                    .then(({data})=>{
                        this.data=data.result
                    })
            },
            change (row,index) {
                this.ReturnReason=row;
                axios.post("/ord/reason/update",this.ReturnReason)
                    .then(({data})=>{
                        iview.Message.success({content:data.msg});
                        this.getList()
                    })
            },
            add(){
                this.ReturnReason={};
                this.modaladd=true
            },
            doadd(){
                axios.post("/ord/reason/add",this.ReturnReason)
                    .then(({data})=>{
                        iview.Message.success({content:data.msg});
                        this.getList()
                    })
            },
            del(row,index){
                let _this = this;
                iview.Modal.confirm({
                    title:"确定是否要删除?",
                    content:"操作不可逆，删不删？",
                    onOk(){
                        axios.post("/ord/reason/delete?id="+row.id)
                            .then(({data})=>{
                                if (data.code == 1000) {
                                    iview.Message.success({content:data.msg});
                                    if(index==0){
                                        if(_this.pageNo!=1){
                                            _this.pageNo=_this.pageNo-1;
                                        }
                                    };
                                    _this.getList()
                                }else {
                                    iview.Message.error({content: data.msg});
                                }
                            })
                    },
                    onCancel(){
                        iview.Message.info("取消删除")
                    }
                })
            },
            update(row,index){
                this.ReturnReason=row;
                this.modalupdate=true
            },
            doupdate(){
                axios.post("/ord/reason/update2",this.ReturnReason)
                    .then(({data})=>{
                        iview.Message.success({content:data.msg});
                       this.getList()
                    })
            },
            noupdate(){
                iview.Message.info("已取消");
                this.getList()
            }


        }
    })
</script>
</html>
